import Router from 'koa-router';
import proxyService from '../../common/proxyService';
import {
  getComplaintPageList,
  getComplaintInfo,
  removeComplaint,
  getComplaintActive,
  getComplaintType,
} from '../../api/manage_complaint';
const router = new Router();

const moduleMap = {
  1: '裂变宝',
  2: '排行榜',
  3: '智能表单',
  5: '任务奖励',
};
const complaintReasonMap = {
  101: '欺诈',
  102: '色情',
  103: '诱导行为',
  104: '不实信息',
  105: '违法犯罪',
  106: '骚扰',
  107: '其他',
};
const complaintTypeMap = {
  10101: '多级分销',
  10102: '网络借贷',
  10103: '兼职赚钱',
  10104: '高额返利',
  10105: '相亲交友',
  10106: '虚假活动',
  10107: '高收益理财',
  10108: '微盘微交易',
  10109: '不在以上类型中',
  10301: '诱导分享',
  10302: '诱导关注',
  10401: '政治类不实消息',
  10402: '医疗健康类不实消息',
  10403: '社会事件类不实信息',
};
//
router.post('/getComplaintPageList', async ctx => {
  const response = await proxyService.postProxy(ctx, getComplaintPageList);

  if (response.code === 1) {
    response.data.records = (response.data.records || []).map(i => ({
      ...i,
      id: i.id,
      companyName: i.companyName,
      wxAvatar: i.complainantImg,
      wxNickname: '',
      wxName: i.complainantName,
      publicAccountAvatar: i.accountImg,
      publicAccountName: i.accountName,
      module: moduleMap[i.activityType] || '未知',
      complaintAction: i.activityName,
      reason: complaintReasonMap[i.complaintReason],
      type: complaintTypeMap[i.complaintType],
      allowConcat: i.contact,
      compllaintTime: i.createTime,
    }));
  }

  return (ctx.body = response);
});

//
router.post('/getComplaintInfo', async ctx => {
  const response = await proxyService.postProxy(ctx, getComplaintInfo);
  if (response.code === 1) {
    let data = response.data || {};
    response.data = {
      ...data,
      wxAvatar: data.complainantImg,
      wxNickname: '',
      wxName: data.complainantName,
      module: moduleMap[data.activityType] || '未知',
      complaintAction: data.activityName,

      reason: complaintReasonMap[data.complaintReason],
      type: complaintTypeMap[data.complaintType],

      publicAccountAvatar: data.accountImg,
      publicAccountName: data.accountName,
      content: data.complaintContent,
      pics: data.evidenceImgList || [],
      link: data.evidenceUrl,
      lostMoney: data.money,
      allowConcat: data.contact,
      compllaintTime: data.createTime,
    };
  }
  return (ctx.body = response);
});

//
router.post('/removeComplaint', async ctx => {
  const response = await proxyService.postProxy(ctx, removeComplaint);
  return (ctx.body = response);
});

router.post('/getComplaintActive', async ctx => {
  const response = await proxyService.postProxy(ctx, getComplaintActive);
  if (response.code === 1) {
    let records = response.data || [];
    response.data = {};
    response.data.records = records.map(i => ({
      ...i,
      value: i.id,
      label: i.name,
    }));
  }

  return (ctx.body = response);
});

router.post('/getComplaintType', async ctx => {
  const response = await proxyService.postProxy(ctx, getComplaintType);
  if (response.code === 1) {
    let records = response.data || [];
    response.data = {};
    response.data.records = records.map(i => ({
      ...i,
      value: i.itemValue,
      label: i.itemName,
    }));
  }

  return (ctx.body = response);
});

export default router;
